home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / src / api / novia_nrc_api.c < prev    next >
Text File  |  1999-12-06  |  6KB  |  264 lines

  1. #include <time.h>
  2. #include <devices/timer.h>
  3. #include <pragma/timer_lib.h>
  4. #include <clib/timer_protos.h>
  5. #include <exec/types.h>
  6. #include <exec/io.h>
  7. #include <exec/memory.h>
  8. #include <devices/conunit.h>
  9. #include <intuition/intuition.h>
  10. #include <dos/dos.h>
  11. #include <libraries/fifo.h>
  12. #include <pragma/exec_lib.h>
  13. #include <pragma/graphics_lib.h>
  14. #include <pragma/dos_lib.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <novia/novia_global.h>
  19. #include <novia/novia_misc.h>
  20. #include <novia/novia_funcs.h>
  21. #include <novia/novia_gui.h>
  22. #include <novia/novia_registers.h>
  23. #include <pragma/noviasys_lib.h>
  24.  
  25. extern struct NRCServer *nrcserver;
  26. extern struct Task *MainTask;
  27.  
  28. void OpenConference();
  29.  
  30. #define YELL             1
  31. #define WHISPER         2
  32. #define BBSCOMMAND    4
  33. #define SIGNAL            8
  34.  
  35. void OpenConference()
  36. {
  37.     struct PortData *cport=(PortData *)FindTask(NULL)->tc_UserData;
  38.     char buffer[80];
  39.     char quit=FALSE;
  40.     struct RCMessage *rcmsg=AllocVec(sizeof(RCMessage),MEMF_ANY|MEMF_CLEAR);
  41.     struct RCMessage2 *msg=NULL;
  42.     struct Room *room=NULL;
  43.     ULONG UserID=0;
  44.     UWORD RoomID=0;
  45.     ULONG users=0;
  46.     ULONG counter=0;
  47.     ULONG    cmdid;
  48.     BOOL nostdcmd=TRUE;
  49.     struct MsgPort *myrcport=CreateMsgPort();
  50.     struct RoomUser *user=NULL;
  51.     ULONG sb_myrcport=0;
  52.     BOOL logoff_send=FALSE;
  53.     if (nrcserver && nrcserver->ServerOpen && myrcport)
  54.     {
  55.         sb_myrcport=1<<myrcport->mp_SigBit;
  56.         ioprintf("\nChecking authentication on NRC-Server.\n");
  57.         ioprintf("please wait and smoke a cigarette, this could take 2-3 microseconds ...\n");
  58.         rcmsg->msgtype=RCMSG_LOGIN;
  59.         rcmsg->flag_internal=TRUE;
  60.         rcmsg->data_len=0;
  61.         strcpy(rcmsg->FromName,cport->LocalUser.Handle);
  62.         if (SendRCMsg(myrcport, rcmsg))
  63.         {
  64.             while (counter<20 && !(msg=(RCMessage2 *)GetMsg(myrcport)))
  65.             {
  66.                 Delay(5);
  67.                 counter++;
  68.             }
  69.             if (msg)
  70.             {
  71.                 if (msg->rcmsg.msgtype==RCMSG_LOGIN_REPLY_OK)
  72.                 {
  73.                     ioprintf("nrc login ok\n");
  74.                     user=msg->rcmsg.user;
  75.                     rcmsg->user=user;
  76.                     rcmsg->user->cport=cport;
  77.                     rcmsg->FromUser=msg->rcmsg.ToUser;
  78.                     rcmsg->FromRoom=msg->rcmsg.ToRoom;
  79.                     rcmsg->ToRoom=msg->rcmsg.ToRoom;
  80.                 }
  81.                 else
  82.                 {
  83.                     ioprintf("Can't open connection. connection aborted by server.\n");
  84.                     quit=TRUE;
  85.                 }
  86.             }
  87.             else
  88.             {
  89.                 quit=TRUE;
  90.                 ioprintf("Can't open connection. out of time.\n");
  91.             }
  92.         }
  93.         while (!quit)
  94.         {
  95.             if ((cport->ProgramClose | !cport->network.online | user->flag_quit))
  96.             {
  97.                 if (!logoff_send)
  98.                 {
  99.                     rcmsg->data_len=0;
  100.                     rcmsg->msgtype=RCMSG_LOGOFF;
  101.                     SendRCMsg(myrcport, rcmsg);
  102.                     logoff_send=TRUE;
  103.                 }
  104.                 else
  105.                     Delay(5);
  106.             }
  107.             else
  108.             {
  109.                 nostdcmd=TRUE;
  110.                 switch (nrc_getline(rcmsg,buffer,80,sb_myrcport))
  111.                 {
  112.                     case BBSCOMMAND:
  113.                         cmdid=GetCommandID(buffer);
  114.                         switch (cmdid)
  115.                         {
  116.                             case    CMD_QUIT:
  117.                                 user->flag_quit=TRUE;
  118.                                 nostdcmd=TRUE;
  119.                                 break;
  120.                             case    CMD_LIST:
  121.                                 ioprintf("Total users: %d, %d\n",nrcserver->users);
  122.                                 room=(Room *)nrcserver->roomlist->lh_Head;
  123.                                 while (room->ln_Succ)
  124.                                 {
  125.                                     ioprintf("RoomNo: %d, RoomName: %s, Users: %d\n",room->RoomID,room->RoomName,room->users);
  126.                                     room=room->ln_Succ;
  127.                                 }
  128.                                 nostdcmd=TRUE;
  129.                                 break;
  130.                             case    CMD_HELP:
  131.                                 nostdcmd=TRUE;
  132.                                 break;
  133.                         }
  134.                         if (nostdcmd)
  135.                         {    
  136.                             if (*buffer=='R'|*buffer=='r')
  137.                             {
  138.                                 LONG newroom;
  139.                                 StrToLong(buffer+1,&newroom);
  140.                                 if (newroom)
  141.                                 {
  142.                                     rcmsg->msgtype=RCMSG_CHANGEROOM;
  143.                                     rcmsg->flag_internal=TRUE;
  144.                                     rcmsg->data_len=0;
  145.                                     rcmsg->aptrdata=(APTR)newroom;
  146.                                     SendRCMsg(myrcport, rcmsg);
  147.                                 }
  148.                             }
  149.                             else
  150.                             {
  151.                                 if (!StdCommand(cmdid) && strlen(buffer))
  152.                                 {
  153.                                     ioprintf("%s: Unknown command\n",buffer);
  154.                                 }
  155.                             }
  156.                         }        
  157.                         ClearMemQuick(buffer,80);
  158.                         break;
  159.                 }
  160.             }
  161.             while(msg=(RCMessage2 *)GetMsg(myrcport))
  162.             {
  163.                 if (msg->msg.mn_ReplyPort==myrcport)
  164.                 {
  165.                     if (msg->rcmsg.msgtype==RCMSG_LOGOFF_OK)
  166.                     {
  167.                         quit=TRUE;
  168.                     }
  169.                     FreeVec(msg);
  170.                 }
  171.                 else
  172.                 {
  173.                     switch (msg->rcmsg.msgtype)
  174.                     {
  175.                         case RCMSG_TEXT:
  176.                             if (msg->rcmsg.flag_sysmsg)
  177.                             {
  178.                             }
  179.                             else
  180.                             {
  181.                                 if (msg->rcmsg.flag_anonymous)
  182.                                 {
  183.                                     ioprintf("z5c7Anonymous:c3z0");
  184.                                 }
  185.                                 else
  186.                                 {
  187.                                     if (msg->rcmsg.FromName)
  188.                                     {
  189.                                         ioprintf("z4c7%s:c3z0",msg->rcmsg.FromName);
  190. //                                        if (msg->rcmsg.flag_realname)
  191. //                                            ioprintf("(%s)",msg->rcmsg.FromRealName);
  192.                                     }
  193.                                     else
  194.                                     {
  195.                                         ioprintf("z5c7Unknown:c3z0");                                
  196.                                     }
  197.                                 }
  198.                                 if (msg->rcmsg.ToName)
  199.                                 {
  200.                                     if (msg->rcmsg.flag_private)
  201.                                     {
  202.                                         ioprintf("(c1PRIVc3)");
  203.                                     }
  204.                                     else
  205.                                     {
  206.                                         ioprintf("(to %s)",msg->rcmsg.ToName);
  207. //                                        if (msg->rcmsg.flag_realname)
  208. //                                            ioprintf("(%s) ",msg->rcmsg.ToRealName);
  209.                                     }
  210.                                 }
  211.                                 if (msg->rcmsg.flag_broadcast)
  212.                                     ioprintf("(BROADCAST)");
  213.                             }
  214.                             ioprintf("c7%s\n",msg->rcmsg.data);
  215.                             break;
  216.                         case RCMSG_CHANGEROOM_OK:
  217.                             user=msg->rcmsg.user;
  218.                             rcmsg->user->cport=cport;
  219.                             rcmsg->FromUser=msg->rcmsg.ToUser;
  220.                             rcmsg->FromRoom=msg->rcmsg.ToRoom;
  221.                             rcmsg->ToRoom=msg->rcmsg.ToRoom;
  222.                             ioprintf("c7%s\n",msg->rcmsg.data);
  223.                             break;
  224.                         case RCMSG_CHANGEROOM_FAILAT:
  225.                             ioprintf("c7%s\n",msg->rcmsg.data);
  226.                             break;
  227.                     }
  228.                     ReplyMsg((Message *)msg);
  229.                 }
  230.             }
  231.             if (*buffer=='/')
  232.             {
  233.                 if (buffer[1]==81)
  234.                 {
  235. //                    quit=TRUE;
  236.                 }
  237.                 else
  238.                 {
  239.                     if (FindArg("WHO",&buffer[1]))
  240.                     {
  241.                     }
  242.                 }
  243.             
  244.             }
  245.             else
  246.             {
  247.                 if (strlen(buffer))
  248.                 {
  249.                     SendRCText(myrcport,rcmsg,buffer);
  250.                 }
  251.             }
  252.         }
  253.     }
  254.  
  255.     /*** end ***/
  256.  
  257.     if (rcmsg)
  258.         FreeVec(rcmsg);
  259.  
  260.     if (myrcport)
  261.         DeleteMsgPort(myrcport);
  262.     
  263. }
  264.